package guda.demox.web.config;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

/**
 * Created by well on 17/6/27.
 */
@Aspect
@Configuration
public class MethodLogAspect {

    private Logger logger = LoggerFactory.getLogger("method");

    @Pointcut("execution(public * guda.demox.biz..*(..)) or execution(public * guda.demox.dal..*(..))")
    public void methodLog() {
    }


    @Around("methodLog()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();
        long time = System.currentTimeMillis()-start;
        logger.info("class:{},method:{},time:{},param:{},result:{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName()
                , time,JSON.toJSONString(joinPoint.getArgs()), JSON.toJSONString(proceed));
        return proceed;

    }


}
